package com.lening.organization.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lening.common.base.BaseController;
import com.lening.common.web.Result;
import com.lening.organization.dto.RoleDTO;
import com.lening.organization.dto.RoleMenuDTO;
import com.lening.organization.po.Role;
import com.lening.organization.service.RoleService;
import com.lening.organization.service.impl.RoleServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("role")
public class RoleController extends BaseController<Role, RoleDTO, RoleServiceImpl> {

    @Resource
    private RoleService roleService;

    @GetMapping(value = "findRole")
    public Page<Role> findRole(Integer pageNum, Integer pageSize, Page<RoleDTO> roleDTO) {
        Page<Role> roleList = roleService.findRole(pageNum, pageSize, roleDTO);
        return roleList;
    }

//    @Operation(summary = "查询全部角色及根据id查询岗位的全部角色")
    @GetMapping("/findRoleAll/{id}")
    public Result findRoleAll(@PathVariable Integer id){
        Map<String, Object> allRole = roleService.findAllRole(id);
        return Result.ok(allRole);
    }

//    @Operation(summary = "查询所有的菜单数据及查询当前角色的菜单数据")
    @GetMapping("/findRoleMenuByRoleId/{roleId}")
    public Result findRoleMenuByRoleId(@PathVariable Integer roleId){
        Map<String, Object> RoleMenuByRoleId = roleService.findRoleMenuByRoleId(roleId);
        return Result.ok(RoleMenuByRoleId);
    }


//    @Operation(summary = "角色添加权限菜单")
    @PostMapping("/addRoleMenu")
    public Result addRoleMenu(@RequestBody RoleMenuDTO roleMenuDTO){
        roleService.addRoleMenu(roleMenuDTO);
        return Result.ok(null);
    }


}
